package com.waimai.app.qa.data;

import java.io.File;
import java.util.HashMap;

/**
 * @author AiHui
 * 
 */
public class Helper {
	public static CsvOperate cop = new CsvOperate();
	public static final String pageFilePath = "resources/testdata/pages";
	public static final String csv = ".csv";
	public static String pagePackage = "com.waimai.app.qa.page";
	public static final String testDataEncoding = "UTF-8";

	public static HashMap<String, Object> getTestData(String inFileName) {
		return cop.deserialize(inFileName, testDataEncoding);
	}

	public PageObject getPage(String pageName) {
		//增加pagePackage配置，用户可以自定义page类所在包名
        //如果配置文件中定义了pagePackage，则用定义的，如果没有定义则用"com.jd.pop.qa.page"
        pagePackage =  System.getProperty("Project.pagePackage",pagePackage);
		
		PageObject page = null;
		try {
			//java反射机制，通过类名生成java类
			page = (PageObject) Class.forName(pagePackage +"." + pageName).newInstance();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		page.init(getTestData(pageFilePath + File.separator + pageName + csv));
		return page;
	}
}
